//
// Created by Eric on 2023/1/21.
// 管理所有文明的数据库
//

#ifndef UUU_CIVILIZATIONSET_H
#define UUU_CIVILIZATIONSET_H
#include <vector>
#include <unordered_map>
#include "Civilization.h"
#include "Counter.h"
#include "uuu_utility.h"

class CivilizationSet {
public:
    // api
    Civilization& GetCivilization(int idx){
        return civilizations[idx];
    }

private:
    // data
    std::unordered_map<int, Civilization> civilizations;
    DatabaseInfo* p_dbi_;

public:
    // 构造方法
    CivilizationSet();
    void Initialize(DatabaseInfo* p_dbi);

public:
    // getter & setter
    double GetTechnologyLevel(int idx){
        return civilizations[idx].technology_level();
    }

public:
    // 迭代器
    auto begin(){
        return civilizations.begin();
    }

    auto end(){
        return civilizations.end();
    }

public:
    // api
    auto MilitaryLagBehind(int a, int b){
        return civilizations[a].MilitaryLagBehind(civilizations[b]);
    }

};

CivilizationSet::CivilizationSet() {

}

void CivilizationSet::Initialize(DatabaseInfo* p_dbi) {
    p_dbi_ = p_dbi;
//    auto noc = dbi.num_of_civilization;
//    num_of_civilization_ = noc;
//    // 生成noc个天体
//    for(int cz_idx = 0; cz_idx < noc;cz_idx++){
//        civilizations[cz_idx] = Civilization::CreateInitialCivilization(cz_idx, Counter::first_technology_level(), Counter::first_military_level(), Counter::first_energy(), Counter::first_warlike(), Counter::first_intelligence());
//    }

// 测试用
civilizations[0] = Civilization::CreateInitialCivilization(0,"A",50, 30, 70, 0.6, 50);
civilizations[1] = Civilization::CreateInitialCivilization(1,"B",60, 30, 70, 0.7, 50);
civilizations[2] = Civilization::CreateInitialCivilization(2,"C",70,30, 70, 0.2, 50);
civilizations[3] = Civilization::CreateInitialCivilization(3,"D",60,100,70,1.0, 50);
civilizations[4] = Civilization::CreateInitialCivilization(4, "E",30, 30, 70, 0.5, 70);
}

#endif //UUU_CIVILIZATIONSET_H
